package com.myopen.controller.admin;

import java.util.List;

import com.jfinal.core.ActionKey;
import com.jfinal.plugin.activerecord.Record;
import com.myopen.base.BaseController;
import com.myopen.base.BaseVo;
import com.myopen.model.ProductCategory;

public class ProductCategoryController extends BaseController{
	
	@ActionKey("/admin/shop/category")
	public void index_category(){
		render("/admin/shop/category/index.html");
	}
	
	@ActionKey("/admin/shop/category/tree")
	public void tree_category(){
		
		String categoryId=getPara("categoryId");
		List<Record> treeJson=ProductCategory.dao.getTree(categoryId);
		
		BaseVo baseVo=new BaseVo();
		baseVo.setData(treeJson);
		
		renderJson(baseVo);
	}
	
	@ActionKey("/admin/shop/category/detail")
	public void detail(){
		
		String id=getPara("id");
		
		BaseVo baseVo=new BaseVo();
		Record resource=ProductCategory.dao.getRecordById(id);
		
		Record data=new Record();
		data.set("vo", resource);
		
		baseVo.setData(data);
		renderJson(baseVo);
	}
	
	@ActionKey("/admin/shop/category/save")
	public void save(){
		
		BaseVo baseVo=new BaseVo();
		Record currUser=getAdminUser();
		
		ProductCategory vo=getModel(ProductCategory.class,"",true);
		
		vo=ProductCategory.dao.save(vo, currUser);
		Record data=new Record();
		data.set("vo", vo);
		baseVo.setData(data);
		
		renderJson(baseVo);
	}
	
	@ActionKey("/admin/shop/category/delete")
	public void delete(){
		
		Record currUser=getAdminUser();
		String id=getPara("id");
		ProductCategory.dao.remove(id, currUser);
		
		BaseVo baseVo=new BaseVo();
		renderJson(baseVo);
		
	}
}
